package com.hushao.aimi;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * @description: 校验信息
 * @author: 胡少
 * @create: 2018-06-08 13:38
 **/
@Slf4j
public class ValidUtil {
    public static void valid(BindingResult result)throws Exception{
        if (result.hasErrors()){
            StringBuffer sb = new StringBuffer();
            for(ObjectError error : result.getAllErrors()){
                sb.append(error.getDefaultMessage());
            }
            log.error(sb.toString());
            throw new Exception(sb.toString());
        }
    }
}
